function Iva(data) {
  this._data = data;

  this._createElements();
};

Iva.prototype._createElements = function() {
  var _self = this;

  // Data
  var folder = (this._data && this._data.folder) ? this._data.folder : null;
  var instance_id = (this._data && this._data.instance_id) ? this._data.instance_id : null;
  var width = (this._data && this._data.config && this._data.config.width) ? this._data.config.width : 0;
  var height = (this._data && this._data.config && this._data.config.height) ? this._data.config.height : 0;
  var images = (this._data && this._data.images) ? this._data.images : [];

  var unique = folder + '_' + instance_id + '_';
  // Gui
  this._gui = {};
  this._gui.width = document.getElementById(unique + 'width');
  this._gui.height = document.getElementById(unique + 'height');
  this._gui.update = document.getElementById(unique + 'update');
  this._gui.upload = document.getElementById(unique + 'upload');
  this._gui.uploaded = document.getElementById(unique + 'uploaded');
  // Display
  this._gui.width.value = width;
  this._gui.height.value = height;

  var browse = document.createElement('span');
  var cancel = document.createElement('span');
  browse.id = unique + UploadUtils._defaultButtonPlaceholderId;
  cancel.id = unique + UploadUtils._defaultCancelButtonId;
  this._gui.upload.appendChild(browse);
  this._gui.upload.appendChild(cancel);

  var pos = DOMUtils.findPos(browse);
  var up = null;
  var initFunc = function() {
    var div = document.createElement('div');
    var p = new ModulePopupBox();
    p._open(div, {
      pos : [ pos[0] + 100, pos[1] - 260 ],
      width : 468,
      t : '',
      doc : document
    });
    up = new ModuleUpload(document, div, 468, 260, _self._user, _self._date, {
      u : unique,
      callbackFunc : function() {
        location.reload()
      },
      popupBox : p
    });
  };

  var uu = new UploadUtils(unique);
  uu._uploadUrl = 'plugins/' + folder + '/upload.php';
  uu._buttonImageUrl = 'image/upload/browse.png';
  uu._buttonWidth = 94;
  uu._buttonHeight = 29;
  uu._createInstance(instance_id + '/', {
    instance_id : instance_id
  }, initFunc, function(file, result) {
    up._callbackFunc(file, result);
  });

  var td, div, img, span, p, size;
  for ( var i = 0, il = images.length; i < il; i++) {
    var tmp = images[i];

    if (this._gui.uploaded.rows.length == 0) {
      td = this._gui.uploaded.insertRow(-1).insertCell(-1);
    } else if (this._gui.uploaded.rows[this._gui.uploaded.rows.length - 1].cells.length < 5) {
      td = this._gui.uploaded.rows[this._gui.uploaded.rows.length - 1].insertCell(-1);
    } else {
      td = this._gui.uploaded.insertRow(-1).insertCell(-1);
    }

    td.align = 'left';
    td.width = '120px';
    td.height = '120px';
    td._item = tmp;
    p = new ModulePopupBoxSimpleTip();
    td.onmouseover = function() {
      var div = document.createElement('div');
      div.appendChild(document.createTextNode(this._item.name + ', ' + this._item.size / 1000 + 'KB'));
      var pos = DOMUtils.findPos(this)
      p._open(div, {
        pos : [ pos[0] + 100, pos[1] + 100 ]
      });
    };
    td.onmouseout = function() {
      p._close();
    };

    size = MiscUtils.decrease( [ tmp.width, tmp.height ], [ 100, 100 ]);
    img = document.createElement('img');
    img.width = size[0];
    img.height = size[1];
    img.src = 'http://{{$smarty.const.DOMAIN|escape:'javascript'}}{{$smarty.const.PATH|escape:'javascript'}}' + 'plugins/' + folder + '/' + tmp.link;
    td.appendChild(img);
    div = document.createElement('div');
    div.appendChild(document.createTextNode(MiscUtils.filename(tmp.name, 12)));
    img = document.createElement('img');
    img.style.cursor = 'pointer';
    img.style.margin = '0 5px';
    img.src = 'image/delete.png';
    img._item = tmp;
    img.onclick = function() {
      new RequestUtils()._custom('delete', JSON.stringify(this._item), function(result, params) {
        location.reload();
      }, {
        pos : DOMUtils.findPos(this),
        php : 'plugins/' + folder + '/server.php'
      });
    };
    div.appendChild(img);
    td.appendChild(div);
  }
  // Event
  this._gui.width.onchange = function() {
    _self._data.config.width = this.value;
  };
  this._gui.height.onchange = function() {
    _self._data.config.height = this.value;
  };
  // Submit
  this._gui.update.onclick = function() {
    new RequestUtils()._write(JSON.stringify( [ {
      n : Constant.TABLE_NAME_PREFIX_PLUGIN + folder + '_config',
      a : [ _self._data.config ],
      r : []
    } ]), function(result, params) {
      location.reload();
    }, {
      pos : DOMUtils.findPos(this)
    });
  };
};
